{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": "             总行名字    地级市  分行数量\n0      中国银行股份有限公司     阜阳    20\n1      中国银行股份有限公司   阿拉善盟     8\n2      中国银行股份有限公司    马鞍山    20\n3      中国银行股份有限公司    驻马店    20\n4      中国银行股份有限公司     聊城    20\n...           ...    ...   ...\n91771  贵州银行股份有限公司  南充蓬安县     0\n91772  贵州银行股份有限公司  南充西充县     0\n91773  贵州银行股份有限公司     蒙自     0\n91774  贵州银行股份有限公司     个旧     0\n91775  贵州银行股份有限公司     开远     0\n\n[91776 rows x 3 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>总行名字</th>\n      <th>地级市</th>\n      <th>分行数量</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>中国银行股份有限公司</td>\n      <td>阜阳</td>\n      <td>20</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>中国银行股份有限公司</td>\n      <td>阿拉善盟</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>中国银行股份有限公司</td>\n      <td>马鞍山</td>\n      <td>20</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>中国银行股份有限公司</td>\n      <td>驻马店</td>\n      <td>20</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>中国银行股份有限公司</td>\n      <td>聊城</td>\n      <td>20</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>91771</th>\n      <td>贵州银行股份有限公司</td>\n      <td>南充蓬安县</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>91772</th>\n      <td>贵州银行股份有限公司</td>\n      <td>南充西充县</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>91773</th>\n      <td>贵州银行股份有限公司</td>\n      <td>蒙自</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>91774</th>\n      <td>贵州银行股份有限公司</td>\n      <td>个旧</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>91775</th>\n      <td>贵州银行股份有限公司</td>\n      <td>开远</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n<p>91776 rows × 3 columns</p>\n</div>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pandas import pandas as pd\n",
    "数量汇总 = pd.read_csv('分行地级市数量汇总(1).csv')\n",
    "数量汇总"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 1. 获取所有总行的名字然后去重"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         总行名字\n",
      "0  中国银行股份有限公司\n"
     ]
    }
   ],
   "source": [
    "print(数量汇总.iloc[:1,:1])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 2. 获取所有地级市的名字然后去重"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 3. 获取整个表格分行数量的总数"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 4. 获取单个总行的所有分行数量"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 5. 获取总行和地级市的数量"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 6. 写一个函数，参数为 总行名字 和 地级市名字，返回值为该总行在这个地级市的数量"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "data": {
      "text/plain": "         总行名字  地级市  分行数量\n2  中国银行股份有限公司  马鞍山    20",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>总行名字</th>\n      <th>地级市</th>\n      <th>分行数量</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2</th>\n      <td>中国银行股份有限公司</td>\n      <td>马鞍山</td>\n      <td>20</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数量汇总[数量汇总['总行名字'] == '中国银行股份有限公司'][数量汇总['地级市'] == '马鞍山']\n",
    "# 数量汇总[(数量汇总['总行名字'] == '中国银行股份有限公司') & ( 数量汇总['地级市'] == '马鞍山')]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 7. 获取单个地级市所有总行的分行数量"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/xb/s5cpmrqn1vj9yh0f4vk581tm0000gn/T/ipykernel_61347/3979402208.py:1: FutureWarning: The default value of numeric_only in DataFrameGroupBy.sum is deprecated. In a future version, numeric_only will default to False. Either specify numeric_only or select only columns which should be valid for the function.\n",
      "  数量汇总.groupby('地级市').sum()\n"
     ]
    },
    {
     "data": {
      "text/plain": "     分行数量\n地级市      \n七台河   106\n万宁     16\n三亚     95\n三明    292\n三沙      2\n..    ...\n龙岩    263\n龙并     13\n龙泉      2\n龙海      1\n龙游      1\n\n[716 rows x 1 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>分行数量</th>\n    </tr>\n    <tr>\n      <th>地级市</th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>七台河</th>\n      <td>106</td>\n    </tr>\n    <tr>\n      <th>万宁</th>\n      <td>16</td>\n    </tr>\n    <tr>\n      <th>三亚</th>\n      <td>95</td>\n    </tr>\n    <tr>\n      <th>三明</th>\n      <td>292</td>\n    </tr>\n    <tr>\n      <th>三沙</th>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>龙岩</th>\n      <td>263</td>\n    </tr>\n    <tr>\n      <th>龙并</th>\n      <td>13</td>\n    </tr>\n    <tr>\n      <th>龙泉</th>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>龙海</th>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>龙游</th>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n<p>716 rows × 1 columns</p>\n</div>"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
